﻿//-----------------------------------------------------------------------
// <copyright file="ConsoleManagerTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using GateShift.Servers.GameServer;
using GateShift.Servers.GameServer.LoggingSystem;
using GateShift.Servers.GameServer.Managers.Consoles;
using GateShift.Services.SDK.Services.HostIntegration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

#endregion

namespace GateShift.Testing.Servers.GameServer.Managers
{
    /// <summary>
    /// Unit Test Class for ConsoleManagerTest
    /// </summary>
    [TestClass]
    public class ConsoleManagerTest
    {
        private ConsoleManager _manager;
        private ConsoleManager_Accessor _accessor;
        private MockFactory _mocks;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        /// <summary>
        /// Use TestInitialize to run code before running each test 
        /// </summary>
        [TestInitialize]
        public void MyTestInitialize()
        {
            _manager = new ConsoleManager();
            _accessor = ConsoleManager_Accessor.AttachShadow(_manager);
            _mocks = new MockFactory(MockBehavior.Strict);
        }

        /// <summary>
        /// Use TestCleanup to run code after each test has run
        /// </summary>
        [TestCleanup]
        public void MyTestCleanup()
        {
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Test for NormalConstructor on Initializing Variables
        /// </summary>
        [TestMethod]
        public void NormalConstructor_InitializesVariables()
        {
            ConsoleManager_Accessor mgr = new ConsoleManager_Accessor();

            Assert.IsNotNull(mgr._updates);
            Assert.AreEqual(0, mgr._updates.Count);
            Assert.IsNotNull(mgr._cliHandlers);
            Assert.AreEqual(0, mgr._cliHandlers.Count);
            Assert.IsNotNull(mgr._recentCommands);
            Assert.AreEqual(0, mgr._recentCommands.Count);
            Assert.AreEqual(string.Empty, mgr._currentCommand);
            Assert.AreEqual(false, mgr._isUpdating);
        }

        /// <summary>
        /// Test for StaticConstructor on Initializing Variables
        /// </summary>
        [TestMethod]
        public void StaticConstructor_InitializesVariables()
        {
            Assert.IsNotNull(ConsoleManager_Accessor._syncCLI);
            Assert.AreNotEqual(0, ConsoleManager_Accessor._consoleHeight);
            Assert.AreNotEqual(0, ConsoleManager_Accessor._consoleWidth);
            Assert.AreNotEqual(0, ConsoleManager_Accessor._logCountMaximum);
        }

        #endregion

        #region AddEventLog

        /// <summary>
        /// Test for AddEventLog on adding a single log
        /// </summary>
        [TestMethod]
        public void AddEventLog_SingleLog()
        {
            Assert.AreEqual(0, _accessor._eventLog.Count);
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            Assert.AreEqual(1, _accessor._eventLog.Count);
        }

        /// <summary>
        /// Test for AddEventLog on adding multiple logs
        /// </summary>
        [TestMethod]
        public void AddEventLog_MultipleLog()
        {
            Assert.AreEqual(0, _accessor._eventLog.Count);
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            Assert.AreEqual(5, _accessor._eventLog.Count);
        }

        /// <summary>
        /// Test for AddEventLog on adding maximum logs visible plus one more
        /// </summary>
        [TestMethod]
        public void AddEventLog_MaximumLogsPlusOne()
        {
            Assert.AreEqual(0, _accessor._eventLog.Count);

            // Add the maximum
            while (_accessor._eventLog.Count < ConsoleManager_Accessor._logCountMaximum)
            {
                _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            }

            // This should still result in 49 in the queue
            _manager.AddEventLog(new LogMessage("Test", "Test", 0, 0, TraceEventType.Information));
            Assert.AreEqual(ConsoleManager_Accessor._logCountMaximum, _accessor._eventLog.Count);
        }

        #endregion

        #region GetCommandForDisplay

        /// <summary>
        /// Test for GetCommandForDisplay with less than the screen width max
        /// </summary>
        [TestMethod]
        public void GetCommandForDisplay_LessThanMaxWidth()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 7, 'A');

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 7, _accessor.GetCommandForDisplay().Length);
        }

        /// <summary>
        /// Test for GetCommandForDisplay with equal to the screen width max
        /// </summary>
        [TestMethod]
        public void GetCommandForDisplay_EqualToMaxWidth()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 6, 'A');

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 6, _accessor.GetCommandForDisplay().Length);
        }

        /// <summary>
        /// Test for GetCommandForDisplay with more than the screen width max with cursor at the beginning
        /// </summary>
        [TestMethod]
        public void GetCommandForDisplay_GreaterThanMaxRow_IndexBeginning()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth * 2, 'A');

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 6, _accessor.GetCommandForDisplay().Length);

            Assert.IsTrue(_accessor.GetCommandForDisplay().EndsWith("..."));
            Assert.IsFalse(_accessor.GetCommandForDisplay().StartsWith("..."));
        }

        /// <summary>
        /// Test for GetCommandForDisplay with more than the screen width max with cursor at the end
        /// </summary>
        [TestMethod]
        public void GetCommandForDisplay_GreaterThanMaxRow_IndexEnding()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth * 2, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length - 1;

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 6, _accessor.GetCommandForDisplay().Length);

            Assert.IsFalse(_accessor.GetCommandForDisplay().EndsWith("..."));
            Assert.IsTrue(_accessor.GetCommandForDisplay().StartsWith("..."));
        }

        /// <summary>
        /// Test for GetCommandForDisplay with more than the screen width max with cursor in the middle
        /// </summary>
        [TestMethod]
        public void GetCommandForDisplay_GreaterThanMaxRow_IndexMiddle()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth * 2, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length / 2;

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 6, _accessor.GetCommandForDisplay().Length);

            Assert.IsTrue(_accessor.GetCommandForDisplay().EndsWith("..."));
            Assert.IsTrue(_accessor.GetCommandForDisplay().StartsWith("..."));
        }

        #endregion

        #region GetCursorDisplayPosition

        /// <summary>
        /// Test for GetCursorDisplayPosition with less than the screen width max with cursor at the beginning
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_LessThanMaxRow_IndexBeginning()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 7, 'A');

            Assert.AreEqual(0, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with less than the screen width max with cursor at the ending
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_LessThanMaxRow_IndexEnding()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 7, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length;

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 7, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with less than the screen width max with cursor at the middle
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_LessThanMaxRow_IndexMiddle()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 7, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length / 2;

            Assert.AreEqual((_accessor._currentCommand.Length / 2) + 1, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with equal to the screen width max with cursor at the beginning
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_EqualToMaxRow_IndexBeginning()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 6, 'A');

            Assert.AreEqual(0, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with equal to the screen width max with cursor at the ending
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_EqualToMaxRow_IndexEnding()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 6, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length;

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 6, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with equal to the screen width max with cursor at the middle
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_EqualToMaxRow_IndexMiddle()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth - 6, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length / 2;

            Assert.AreEqual((_accessor._currentCommand.Length / 2) + 1, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with greater than the screen width max with cursor at the beginning
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_GreaterThanMaxRow_IndexBeginning()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth * 2, 'A');

            Assert.AreEqual(0, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with greater than the screen width max with cursor at the ending
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_GreaterThanMaxRow_IndexEnding()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth * 2, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length;

            Assert.AreEqual(ConsoleManager_Accessor._consoleWidth - 6, _accessor.GetCursorDisplayPosition());
        }

        /// <summary>
        /// Test for GetCursorDisplayPosition with greater than the screen width max with cursor at the middle
        /// </summary>
        [TestMethod]
        public void GetCursorDisplayPosition_GreaterThanMaxRow_IndexMiddle()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = string.Empty.PadRight(ConsoleManager_Accessor._consoleWidth * 2, 'A');
            _accessor._currentCursorIndex = _accessor._currentCommand.Length / 2;

            Assert.AreEqual(((ConsoleManager_Accessor._consoleWidth - 6) / 2), _accessor.GetCursorDisplayPosition());
        }

        #endregion

        #region ProcessNormalKeyInput

        /// <summary>
        /// Test for ProcessNormalKeyInput with the delete key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_DeleteKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = "Test Command";
            _accessor._currentCursorIndex = 4;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.Delete, false, false, false));

            Assert.AreEqual("TestCommand", _accessor._currentCommand);
            Assert.AreEqual(4, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the backspace key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_BackSpaceKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = "Test Command";
            _accessor._currentCursorIndex = 4;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.Backspace, false, false, false));

            Assert.AreEqual("Tes Command", _accessor._currentCommand);
            Assert.AreEqual(3, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the enter key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_EnterKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = "Test Command";
            _accessor._currentCursorIndex = 4;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.Enter, false, false, false));

            Assert.AreEqual(string.Empty, _accessor._currentCommand);
            Assert.AreEqual(0, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the escape key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_EscapeKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            // Console command can be no more than console width - 6. 1 extra for unit test
            _accessor._currentCommand = "Test Command";
            _accessor._currentCursorIndex = 4;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.Escape, false, false, false));

            Assert.AreEqual(string.Empty, _accessor._currentCommand);
            Assert.AreEqual(0, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the up arrow key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_UpArrowKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._recentCommands.Enqueue("One");
            _accessor._recentCommands.Enqueue("Two");
            _accessor._recentCommands.Enqueue("Three");
            _accessor._currentCommandIndex = 1;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.UpArrow, false, false, false));

            Assert.AreEqual("Three", _accessor._currentCommand);
            Assert.AreEqual(_accessor._currentCommand.Length - 1, _accessor._currentCursorIndex);
            Assert.AreEqual(2, _accessor._currentCommandIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the down arrow key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_DownArrowKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._recentCommands.Enqueue("One");
            _accessor._recentCommands.Enqueue("Two");
            _accessor._recentCommands.Enqueue("Three");
            _accessor._currentCommandIndex = 1;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.DownArrow, false, false, false));

            Assert.AreEqual("One", _accessor._currentCommand);
            Assert.AreEqual(_accessor._currentCommand.Length - 1, _accessor._currentCursorIndex);
            Assert.AreEqual(0, _accessor._currentCommandIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the left arrow key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_LeftKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._currentCommand = "12345";
            _accessor._currentCursorIndex = 3;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.LeftArrow, false, false, false));

            Assert.AreEqual(2, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the right arrow key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_RightKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._currentCommand = "12345";
            _accessor._currentCursorIndex = 3;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.RightArrow, false, false, false));

            Assert.AreEqual(4, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the home key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_HomeKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._currentCommand = "12345";
            _accessor._currentCursorIndex = 3;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.Home, false, false, false));

            Assert.AreEqual(0, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with the end key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_EndKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._currentCommand = "12345";
            _accessor._currentCursorIndex = 3;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo(new char(), ConsoleKey.End, false, false, false));

            // Ending is actually zero based max index + 1 (Length is 1 based)
            Assert.AreEqual(_accessor._currentCommand.Length, _accessor._currentCursorIndex);
        }

        /// <summary>
        /// Test for ProcessNormalKeyInput with any other key
        /// </summary>
        [TestMethod]
        public void ProcessNormalKeyInput_GeneralKey()
        {
            Assert.AreEqual(0, _accessor._currentCommand.Length);

            _accessor._currentCommand = "Test Command";

            // Ending is actually zero based max index + 1 (Length is 1 based)
            _accessor._currentCursorIndex = _accessor._currentCommand.Length;

            _accessor.ProcessNormalKeyInput(new ConsoleKeyInfo('A', ConsoleKey.A, false, false, false));

            Assert.AreEqual("Test CommandA", _accessor._currentCommand);

            // Ending is actually zero based max index + 1 (Length is 1 based)
            Assert.AreEqual(_accessor._currentCommand.Length, _accessor._currentCursorIndex);
        }

        #endregion

        #region AddConsoleUpdate

        /// <summary>
        /// Test for AddConsoleUpdate with multiple threads
        /// </summary>
        [TestMethod]
        public void AddConsoleUpdate_ThreadTest()
        {
            Assert.AreEqual(0, _accessor._updates.Count);

            for (int x = 0; x < 10; x++)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(t => _accessor.AddConsoleUpdate(ConsoleUpdateType.Header));
            }
        }

        #endregion

        #region UpdateConsole

        /// <summary>
        /// Test for UpdateConsole with removing queued items
        /// </summary>
        [TestMethod]
        public void UpdateConsole_RemovesItemQueue()
        {
            Assert.AreEqual(0, _accessor._updates.Count);
            Console.SetOut(new StringWriter());

            _accessor._initialized = true;
            _accessor._updates.Enqueue(ConsoleUpdateType.Content);
            Assert.AreEqual(1, _accessor._updates.Count);

            _accessor.UpdateConsole();
            Assert.AreEqual(0, _accessor._updates.Count);
        }

        #endregion

        #region ProcessCommand

        /// <summary>
        /// Test for ProcessCommand with failing the processing because of no sub commands
        /// </summary>
        [TestMethod]
        public void ProcessCommand_Fails_NoSubCommands()
        {
            IMock<ICommandLineInterfaceHandler> mock = _mocks.Create<ICommandLineInterfaceHandler>();

            _manager.AddCLIHandler("test", mock.Object);
            _accessor.ProcessCommand("test");

            mock.VerifyAll();
        }

        /// <summary>
        /// Test for ProcessCommand with failing the processing because of no handler
        /// </summary>
        [TestMethod]
        public void ProcessCommand_Fails_NoHandler()
        {
            IMock<ICommandLineInterfaceHandler> mock = _mocks.Create<ICommandLineInterfaceHandler>();

            _manager.AddCLIHandler("test", mock.Object);
            _accessor.ProcessCommand("testint sub");

            mock.VerifyAll();
        }

        /// <summary>
        /// Test for ProcessCommand with succeeding the processing
        /// </summary>
        [TestMethod]
        public void ProcessCommand_Successful()
        {
            IMock<ICommandLineInterfaceHandler> mock = _mocks.Create<ICommandLineInterfaceHandler>();

            mock.Expect(t => t.HandleCommand(It.Is<List<string>>(y => y.Contains("sub") && y.Contains("command")))).Returns(true);

            _manager.AddCLIHandler("test", mock.Object);
            _accessor.ProcessCommand("test sub command");

            mock.VerifyAll();
        }

        #endregion

        #region AddCLIHandler

        /// <summary>
        /// Test for AddCLIHandler with succeeding
        /// </summary>
        [TestMethod]
        public void AddCLIHandler_Successful()
        {
            IMock<ICommandLineInterfaceHandler> mock = _mocks.Create<ICommandLineInterfaceHandler>();

            _manager.AddCLIHandler("test", mock.Object);

            mock.VerifyAll();
        }

        /// <summary>
        /// Test for AddCLIHandler with a null argument of the handler
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void AddCLIHandler_NullHandler()
        {
            _manager.AddCLIHandler("test", null);
        }

        /// <summary>
        /// Test for AddCLIHandler with a null argument of the command root
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void AddCLIHandler_NullRootCommand()
        {
            IMock<ICommandLineInterfaceHandler> mock = _mocks.Create<ICommandLineInterfaceHandler>();

            _manager.AddCLIHandler(null, mock.Object);

            mock.VerifyAll();
        }

        /// <summary>
        /// Test for AddCLIHandler with an empty argument of the root command
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void AddCLIHandler_EmptyRootCommand()
        {
            IMock<ICommandLineInterfaceHandler> mock = _mocks.Create<ICommandLineInterfaceHandler>();

            _manager.AddCLIHandler(string.Empty, mock.Object);

            mock.VerifyAll();
        }

        #endregion

        #region BackGround Threading

        /// <summary>
        /// Test for BackGroundThread
        /// </summary>
        [TestMethod]
        public void BackGroundThread()
        {
            Assert.AreEqual(false, _manager.IsAlive);
            _manager.Start();
            Assert.AreEqual(true, _manager.IsAlive);
            _manager.Stop();
            Assert.AreEqual(false, _manager.IsAlive);
        }

        #endregion
    }
}